<?php
namespace App\Http\Controllers\Api\v1;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
use Hash;

class LoginController extends Controller
{
    /*
     * 登录接口测试
     * @param $request  username,password
     * */
    public function checkLogin(Request $request)
    {
        $username = $request->input('username');
        $password = $request->input('password');

        if(!$username || !$password){
            $result = array(
                'errcode'=> 404,
                'errmsg' => "参数缺失"
            );
            return json_encode($result);
        }
        $where = array(
            'username' => $username,
            'password' => md5($password)
        );
        $userData = DB::table('tf_user')
                -> where($where)
                -> first();
        if($userData){
            $result = array(
                'errcode'=> 0,
                'errmsg' => "登录成功",
                'datas' => $userData
            );
            return json_encode($result);
        }else{
            $result = array(
                'errcode'=> 403,
                'errmsg' => "账户或密码错误",
            );
            return json_encode($result);
        }

    }


}